<!---for the saving of linked eforms in the eDTR--->
<!---by mico--->
<CFOUTPUT>
<CFIF THETABLE NEQ "#GETRECORD.TKFILENAME_FK#PX">
	<CFQUERY name="delDOCS" datasource="#CLIENT.COMPANY_DSN#">
		DELETE FROM ECINDTRUPDATEDTL
		WHERE DOCNUMBER = '#THEDOCNUMBER#'
			AND FORMCODE_FK = '#THEFORMCODE#'
			AND DOCNUMBER_FK IN (#LISTQUALIFY(FORM.HIDDOCNUMS,"'",",")#)
	</CFQUERY>
	<CFIF STRUCTKEYEXISTS(FORM,"chkDOCNUMBER")>
		<CFQUERY NAME="insertDOCS" datasource="#CLIENT.COMPANY_DSN#">
			INSERT INTO ECINDTRUPDATEDTL(PID,DOCNUMBER,FORMCODE_FK,DOCNUMBER_FK,ROUTEID,RECCREATEDBY,RECDATECREATED)
			<CFLOOP list="#FORM.chkDOCNUMBER#" index="DN">
				SELECT '#FORM.hidPID#','#THEDOCNUMBER#','#THEFORMCODE#','#DN#','#THETABLE##DN#','#CLIENT.USERID#',#NOW()# <CFIF DN NEQ LISTLAST(FORM.chkDOCNUMBER)>UNION ALL</CFIF>
			</CFLOOP>
		</CFQUERY>
		<CFLOOP list="#FORM.chkDOCNUMBER#" index="DN">
			<CFQUERY name="updateORIG#DN#" datasource="#CLIENT.COMPANY_DSN#">
				UPDATE #THETABLE#
				SET ROUTEID = '#THETABLE##DN#'
				WHERE DOCNUMBER = '#DN#'
			</CFQUERY>
		</CFLOOP>
	</CFIF>
<CFELSE>
	<CFQUERY name="delDOCS" datasource="#CLIENT.COMPANY_DSN#">
		DELETE FROM ECINDTRUPDATEDTL
		WHERE DOCNUMBER = '#THEDOCNUMBER#'
			AND FORMCODE_FK = '#THETABLE#'
	</CFQUERY>
	<CFIF STRUCTKEYEXISTS(FORM,"SEQUENCENO")>
		<CFQUERY NAME="insertDOCS" datasource="#CLIENT.COMPANY_DSN#">
			INSERT INTO ECINDTRUPDATEDTL(DOCNUMBER,FORMCODE_FK,DOCNUMBER_FK,ROUTEID,RECCREATEDBY,RECDATECREATED)
			<CFLOOP list="#FORM.SEQUENCENO#" index="SN">
				SELECT '#THEDOCNUMBER#','#THETABLE#','#SN#,#EVALUATE("SEL#SN#")#','#THETABLE##SN#','#CLIENT.USERID#',#NOW()# <CFIF SN NEQ LISTLAST(FORM.SEQUENCENO)>UNION ALL</CFIF>
			</CFLOOP>
		</CFQUERY>
	</CFIF>
</CFIF>
</CFOUTPUT>